<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../style.css" type="text/css" />
</head>
<?php
		include_once "../inc/docroot.php";
		include_once PATH."inc/class.autores.inc.php";
		$autores = new autores($db);
		if(isset($_GET['campaign']))$campaign_id = $_GET['campaign'];
		if(isset($_GET['edit']))$edit = $_GET['edit'];
		if(isset($_GET['delete']))$delete = $_GET['delete'];
		if(isset($_GET['activate']))$activate = $_GET['activate'];

?>

<body>
<div>
  <div class="autores_header">
    <?php
		if( !empty($_POST['name']) &&!empty($_POST['sub_master_mail_id']) && isset($campaign_id) && isset($edit) && $edit == 1) {
        	echo "<br /><br />";
			echo $autores->editcampaign($campaign_id);
			?>
			<script>
			window.opener.location.reload();
			window.close();
            </script>
            <?php
	   }
	   else if(isset($campaign_id) && isset($delete) && $delete == 1) {
        	echo "<br /><br />";
			echo $autores->deletecampaign($campaign_id);
			?>
			<script>
			window.opener.location.reload();
			window.close();
            </script>
            <?php
	   }
	   else if(isset($campaign_id) && isset($activate) && ($activate == 0 || $activate == 1)) {
        	echo "<br /><br />";
			echo $autores->campaignactivate($campaign_id, $activate);
			?>
			<script>
			window.opener.location.reload();
			window.close();
            </script>
            <?php
	   }
       else if( !empty($_POST['name']) &&!empty($_POST['sub_master_mail_id'])) {
        	echo "<br /><br />";
			echo $autores->addcampaign();
			?>
			<script>
			window.opener.location.reload();
            </script>
            <?php
	   }
	   else{
    		echo "<br />";
    		echo "<br />";
			if(!isset($delete))
    			echo "<label>Please fill all the fields.</label>";
	   }

    echo "<br />";
    echo "<br />";
	if(isset($campaign_id) && isset($edit) && $edit == 0){
		echo "<label> EDIT CAMPAIGN: " .$campaign_id."</label>";
	}
	else if(isset($campaign_id) && 
				(isset($delete) && $delete == 0) || 
				(isset($activate) && 
					($activate==10 || $activate==11)
				)
			){
		if(isset($delete)){
			echo "<label> Are you sure to DELETE CAMPAIGN: " .$campaign_id."</label>";			
			?>
			<form method="post" action="addnewcampaign.php<?php if(isset($campaign_id) && isset($delete)) echo "?campaign=".$campaign_id."&delete=1";?>" name="deletecampaign" id="deletecampaign">
		  <br /><br />
		  <input type="submit" name="deletecampaign" id="deletecampaign" value="DELETE CAMPAIGN" class="btn btn--blue btn--m" />
			</div>
			<?php
		}
		else {
			if($activate == 10) echo "<label> Do you want to Deactivate CAMPAIGN: " .$campaign_id."</label>";
			else echo "<label> Do you want to Activate CAMPAIGN: " .$campaign_id."</label>";
			$activate = $activate - 10;
			if($activate == 1)$activatestr = "ACTIVATE";
			else $activatestr = "DEACTIVATE";
			?>
			<form method="post" action="addnewcampaign.php<?php if(isset($campaign_id) && isset($activate)) echo "?campaign=".$campaign_id."&activate=".$activate;?>" name="activatecampaign" id="activatecampaign">
		  <br /><br />
		  <input type="submit" name="activatecampaign" id="activatecampaign" value="<?php echo $activatestr?> CAMPAIGN" class="btn btn--blue btn--m" />
			</div>
			<?php
			
		}
		echo "<br/> <br/>";
    }
	else {
    	echo "<label> ADD A NEW CAMPAIGN </label>";
	}
	if(!isset($delete) && !isset($activate)){
?>
  </div>
  <form method="post" action="addnewcampaign.php<?php if(isset($campaign_id) && isset($edit)) echo "?campaign=".$campaign_id."&edit=1";?>" name="addcampaignform" id="addcampaignform">
    <div style="font-size:9px;" align="center"> <br />
      <br />
      <input type="text" name="name" id="name" style="text-align:center"/>
      <label for="name">Name</label>
      <br />
      <br />
      <select name="sub_master_mail_id" id="sub_master_mail_id" width="340" style="width: 340px; height:20px; font-size:13px;" height="20">
        <?php
		if(isset($edit) && isset($campaign_id))
			$autores->sub_master_mail_id_select($edit,$campaign_id);
		else
			$autores->sub_master_mail_id_select();
?>
      </select>
      <br />
      <label for="sub_master_mail_id">POPPING MAIL</label>
      <br />
      <br />
      <br />
      <br/ >
      <input type="submit" name="addcampaigninput" id="addcampaigninput" value="Save campaign" class="btn btn--blue btn--m" />
    </div>
  </form>
  <?php  } ?>
</div>
</body>
